package com.watson.lucene;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.FSDirectory;
import org.wltea.analyzer.lucene.IKAnalyzer;

import java.io.File;
import java.io.IOException;

/**
 * @program: mytest
 * @description: lucene test
 * @author: zhangpeng348@jd.com
 * @date: 2018-12-13 14:13
 **/
public class LuceneTest {


    public static void main(String [] args) {

        LuceneTest luceneTest = new LuceneTest();
        luceneTest.indexTest();


    }
    public void indexTest() {
        try {
            FSDirectory indexDir;
            indexDir = FSDirectory.open(new File("D:/index/test").toPath());

            IKAnalyzer ikAnalyzer = new IKAnalyzer();
            IndexWriterConfig indexWriterConfig = new IndexWriterConfig();

            IndexWriter indexWriter = new IndexWriter(indexDir, indexWriterConfig);
            Document document = new Document();
            document.add(new TextField("aa", "bb", Field.Store.YES));
            indexWriter.addDocument(document);
            indexWriter.commit();
            indexWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
